#include "common.h"
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main()
{
	int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
	if(sock_fd < 0)
		err_sys("socket error\n");

	struct sockaddr_in dest_addr;
	dest_addr.sin_family = AF_INET;
	dest_addr.sin_port = htons(9999);

	int ret = inet_pton(AF_INET, "127.0.0.1", &dest_addr.sin_addr);
	if(ret != 1)
		err_sys("inet_pton error\n");
	
	char buffer[1024];
	while(1)
	{
		bzero(buffer, 1024);
		printf("send : ");
		fgets(buffer, 1024, stdin);

		sendto(sock_fd, buffer, strlen(buffer), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
	}

	close(sock_fd);

	return 0;
}
